﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SBACN.WebSite.Models;
using SBACN.WebSite.Code;
using System.Linq.Expressions;

namespace SBACN.WebSite.Admin
{
	public partial class WebLinkClsList : BasePage
	{
		/// <summary>
		/// 系统字典类型
		/// </summary>
		public string SystemType
		{
			get
			{
				//if (ViewState["SystemType"] == null)
				//    return "00080005";//默认值
				//else
				//    return ViewState["SystemType"].ToString();
				return this.SystemCode;
			}
			private set
			{
				ViewState["SystemType"] = this.SystemCode;
			}
		}

		protected void Page_Load(object sender, EventArgs e)
		{
			if (!AdminBasePage.CheckCodeRight(AdminBasePage.AdminInfo, SystemType))
			{
				AdminBasePage.RedirectWithMessage(AdminDefaultPage, "您没有访问当前页面的权限,请与系统管理员联系!");
				return;
			}
			ShowList(1);
		}
		protected void ShowList(int pageIndex)
		{
			Expression<Func<TB_OutLink, bool>> fun = (p => p.Category == "");
			Expression<Func<TB_OutLink, DateTime>> order = (p => p.CreateDate);
			int records = 0;
			this.LinkList.DataSource = DAL.DALHelper.Instance.GetList<TB_OutLink, DateTime>(fun, order, true, this.Pager1.PageSize, pageIndex, out records);
			this.LinkList.DataBind();
			this.Pager1.RecordCount = records;
			this.Pager1.InitControl();
		}
		public void BindSelectedPageIndexChanged(int pageIndex, int nextPage)
		{
			ShowList(nextPage);
		}

		public void btn_Delete_Click(object sender, EventArgs e)
		{
			int id = Convert.ToInt32(this.hid_ID.Value);
			var result = DAL.DALHelper.Instance.GetObject<TB_OutLink>("ID", id);
			if (result.Status == true)
			{
				result.Status = false;
			}
			else
			{
				result.Status = true;
			}

			DAL.DALHelper.Instance.Update<TB_OutLink>(result);
			DAL.DALHelper.Instance.SaveChanges();
			Response.Redirect(Request.Url.ToString());
		}

		protected void btn_NewsRefresh_Click(object sender, EventArgs e)
		{
			ShowList(this.Pager1.CurrentPageIndex);
		}
	}
}